#include "transport.h"
#include  <cmath>

/*----------------------------------------------------------*/

Transport::Transport() : ProblemInterface()
{
  _a = 0.5;
}

/*----------------------------------------------------------*/

void Transport::initialCondition(Vector& u0, double x) const
{
  if(x < 0.5)
  {
    u0[0] = 1.0;
  }
  else
  {
    u0[0] = -1.0;
  }
}

/*----------------------------------------------------------*/

void Transport::flux(Vector& flux, const Vector& u) const
{
  flux[0] = _a*u[0];
}

/*----------------------------------------------------------*/

void Transport::boundaryfluxleft(Vector& flux, const Vector& u) const
{
  if(_a>0.0)
  {
    flux[0] = _a*1.0;     
  }
  else
  {
    flux[0] = _a*u[0];     
  }
}

/*----------------------------------------------------------*/

void Transport::boundaryfluxright(Vector& flux, const Vector& u) const
{
  if(_a>0.0)
  {
    flux[0] = _a*u[0];     
  }
  else
  {
    flux[0] = _a*(-1.0);     
  }
}

/*----------------------------------------------------------*/

void Transport::interiorflux(Vector& flux, const Vector& ul, const Vector& ur) const
{
  flux[0] = _a*0.5*(ul[0]+ur[0]) + 0.5*fabs(_a)*(ul[0]-ur[0]);
}

